//
//  UserRegistrationManager.m
//  Yiqidianyin
//
//  Created by apple on 15/8/9.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "UserRegistrationManager.h"
#import "AFNetworking.h"




@interface UserRegistrationManager ()

@property(nonatomic,strong)AFHTTPRequestOperationManager *afManager;

@end

@implementation UserRegistrationManager




+(instancetype)share
{
    static UserRegistrationManager *m = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        m = [[UserRegistrationManager alloc]init];
    });
    return m;
}


-(void)RegistrationWithPhonID:(NSString *)phonID BackBlock:(RegistrationManagerBlock)bh
{

  
    self.afManager = [[AFHTTPRequestOperationManager alloc]init];
     self.afManager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString * url =[http stringByAppendingString:@"/mobile/user/sendMobileMessage"];
    
    
    
    NSDictionary * dic =  @{@"phoneNum":phonID};
    

    AFHTTPRequestOperation * op = [self.afManager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@",responseObject);
        
        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        bh(dic);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
    [op start];
}
-(void)registrationWIthPhonID:(NSString *)phonID andVerificationCode:(NSString *)code andPassword:(NSString *)password BackBlock:(RegistrationManagerBlock)bh
{
    self.afManager = [[AFHTTPRequestOperationManager alloc]init];
    self.afManager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *url = [http stringByAppendingString:@"/mobile/user/register"];
    
    NSDictionary * dic =  @{@"phoneNum":phonID,@"code":code,@"password":password};
    
    
    AFHTTPRequestOperation * op1 = [self.afManager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
              NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"%@",dic);
        bh(dic);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
    [op1 start];
}






@end
